package com.oa.ylms.apps.business.archives.impl;

import java.util.List;

import com.oa.ylms.apps.business.archives.IArchiveInfoService;
import com.oa.ylms.apps.business.archives.IRecordCategoryService;
import com.oa.ylms.apps.business.archives.IRecordInfoService;
import com.oa.ylms.apps.common.DateUtil;
import com.oa.ylms.apps.dao.archives.IRecordInfoDao;
import com.oa.ylms.apps.entity.archives.RecordInfoValue;

public class RecordInfoServiceImpl implements IRecordInfoService {
	private IRecordCategoryService recordCategoryService;
	private IArchiveInfoService archiveInfoService;
	private IRecordInfoDao infoDao;
	private RecordInfoValue recordInfo;

	@Override
	public int addRecordInfo(int categoryId, int archiveId, String messages)
			throws Exception {
		recordInfo.setRecordCategory(recordCategoryService.queryByCategoryId(categoryId));
		recordInfo.setArchiveInfo(archiveInfoService.queryByArchiveId(archiveId));
		if(recordInfo.getArchiveInfo() != null && recordInfo.getRecordCategory() != null){
			recordInfo.setMessages(messages);
			recordInfo.setCreateTime(DateUtil.toDate(DateUtil.getCurrentDate()));
			return infoDao.addRecordInfo(recordInfo);
		}
		return 0;
	}

	@Override
	public boolean deleteRecordInfo(int recordId) throws Exception {
		recordInfo = queryByRecordId(recordId);
		if(recordInfo != null){
			return infoDao.deleteRecordInfo(recordInfo);
		}
		return false;
	}

	@Override
	public boolean modifyRecordInfo(int recordId, String messages) throws Exception {
		recordInfo = queryByRecordId(recordId);
		if(recordInfo != null){
			recordInfo.setMessages(messages);
			return infoDao.modifyRecordInfo(recordInfo);
		}
		return false;
	}

	@Override
	public RecordInfoValue queryByRecordId(int recordId) throws Exception {
		recordInfo.setRecordId(recordId);
		return infoDao.queryByRecordId(recordInfo);
	}

	@Override
	public List<RecordInfoValue> queryRecordInfo(Integer categoryId, Integer archiveId)
			throws Exception {
		if(categoryId != null)
		recordInfo.setRecordCategory(recordCategoryService.queryByCategoryId(categoryId));
		if(archiveId != null)
		recordInfo.setArchiveInfo(archiveInfoService.queryByArchiveId(archiveId));
		return infoDao.queryRecordInfo(recordInfo);
	}
	
	
	public IRecordCategoryService getRecordCategoryService() {
		return recordCategoryService;
	}

	public void setRecordCategoryService(
			IRecordCategoryService recordCategoryService) {
		this.recordCategoryService = recordCategoryService;
	}

	public IArchiveInfoService getArchiveInfoService() {
		return archiveInfoService;
	}

	public void setArchiveInfoService(IArchiveInfoService archiveInfoService) {
		this.archiveInfoService = archiveInfoService;
	}

	public IRecordInfoDao getInfoDao() {
		return infoDao;
	}

	public void setInfoDao(IRecordInfoDao infoDao) {
		this.infoDao = infoDao;
	}

	public RecordInfoValue getRecordInfo() {
		return recordInfo;
	}

	public void setRecordInfo(RecordInfoValue recordInfo) {
		this.recordInfo = recordInfo;
	}

}
